package com.cskaoyan.controller.admincontroller;

import com.cskaoyan.bean.po.MarketCategory;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.adminservice.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:J
 * @datetime 2022/12/30 4:54
 * @description: TODO:
 * 商品目录controller层
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    //http://182.92.235.201:8083/admin/category/list
    //http://182.92.235.201:8083/admin/category/l1  --懵
    @RequestMapping("list")
        //id仍是表中主键，单表
    public BaseRespVo list(BasePageInfo info){
            CommonData<MarketCategory> data=categoryService.list(info);
            //errno 0, data:RegionBO, errmsg:"成功"
            return BaseRespVo.okYa(data);

    }
    @RequestMapping("l1")
    public BaseRespVo l1(BasePageInfo info){
        CommonData<MarketCategory> data=categoryService.l1(info);
        return BaseRespVo.okYa(data);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketCategory marketCategory){
        BaseRespVo createMarketCategory=categoryService.create(marketCategory);
        return createMarketCategory;
    }

    /**
     * http://182.92.235.201:8083/admin/category/update
     * post
     * @param marketCategory
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketCategory marketCategory){
        BaseRespVo updateMarketCategory=categoryService.update(marketCategory);
        return updateMarketCategory;
    }

    /**
     * http://182.92.235.201:8083/admin/category/update
     * post
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketCategory marketCategory){
        BaseRespVo deleteCategory=categoryService.delete(marketCategory);
        return deleteCategory;
    }
}
